//
//  NewsTableViewCell.m
//  huien
//
//  Created by yiban on 2017/5/26.
//  Copyright © 2017年 lcb. All rights reserved.
//

#import "NewsTableViewCell.h"
#import "NoticesModel.h"
@interface NewsTableViewCell()
{
    
}
@property(nonatomic,strong)UIView *backgroupView;
@property(nonatomic,strong)UIButton*newLabel;
@property(nonatomic,strong)UIButton*newLabel1;
@property(nonatomic,strong)UIButton*morenewLabel;
@property(nonatomic,strong)UIButton*morenewLabel1;
@property(nonatomic,strong)UIView *bView;
@end
@implementation NewsTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
      
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
}
/// 根据数据模型来显示内容
- (void)showInfo:(id)model indexPath:(NSIndexPath *)indexPath
{
    self.data =model;
    self.indexPath=indexPath;
    //
    NSArray *notices = (NSArray*)model;
    self.backgroupView.frame =CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
   //
    self.newLabel.frame =CGRectMake(10, 20, SCREEN_WIDTH-90, 18);
    self.morenewLabel.frame =CGRectMake(SCREEN_WIDTH-80, 20, 60, 18);
    if (notices.count>0) {
        NoticesModel *noticemodel =[notices objectAtIndex:0];
        [self.newLabel setTitle:noticemodel.investTitle forState:UIControlStateNormal];
        [self.morenewLabel setTitle:noticemodel.investType forState:UIControlStateNormal];
    }
    [self.backgroupView addSubview:self.newLabel];
    [self.backgroupView addSubview:self.morenewLabel];
    self.bView.frame =CGRectMake(10, self.newLabel.frame.origin.y+self.newLabel.frame.size.height+9, SCREEN_WIDTH-20, 1);
    //
    self.newLabel1.frame =CGRectMake(10, self.newLabel.frame.origin.y+36, SCREEN_WIDTH-90, 18);
    self.morenewLabel1.frame =CGRectMake(SCREEN_WIDTH-80, self.newLabel.frame.origin.y+36, 60, 18);
    if (notices.count>1) {
        NoticesModel *noticemodel1 =[notices objectAtIndex:1];
        [self.newLabel1 setTitle:noticemodel1.investTitle forState:UIControlStateNormal];
        [self.morenewLabel1 setTitle:noticemodel1.investType forState:UIControlStateNormal];
    }
    [self.backgroupView addSubview:self.newLabel1];
    [self.backgroupView addSubview:self.morenewLabel1];
}
+(CGFloat)returnCellHeight
{
    return 90;
}
-(void)dealloc
{
    [LcbLog log:@"NewsTableViewCell--------->dealloc"];
}
-(UIView*)backgroupView
{
    if (!_backgroupView) {
        _backgroupView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
        _backgroupView.backgroundColor=[UIColor clearColor];
        [self addSubview:_backgroupView];
    }
    return _backgroupView;
}
-(UIView*)bView
{
    if (!_bView) {
        _bView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 1)];
        _bView.backgroundColor=linecolor;
        [_backgroupView addSubview:_bView];
    }
    return _bView;
}
-(UIButton*)newLabel
{
    if (!_newLabel) {
        _newLabel = [UIButton buttonWithType:UIButtonTypeCustom];
        _newLabel.backgroundColor =[UIColor clearColor];
        _newLabel.tag=1;
        _newLabel.titleLabel.font = [UIFont systemFontOfSize:17];
        [_newLabel setTitleColor:adscolor forState:UIControlStateNormal];
        [_newLabel setTitle:@"" forState:UIControlStateNormal];
//        [_newLabel addTarget:self action:@selector(clickEvent:) forControlEvents:UIControlEventTouchUpInside];
        _newLabel.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
      
    }
    return _newLabel;
}
-(UIButton*)newLabel1
{
    if (!_newLabel1) {
        _newLabel1 = [UIButton buttonWithType:UIButtonTypeCustom];
        _newLabel1.tag=2;
        _newLabel1.backgroundColor =[UIColor clearColor];
        _newLabel1.titleLabel.font = [UIFont systemFontOfSize:17];
        [_newLabel1 setTitleColor:UIColorHex(0xeb9a1a) forState:UIControlStateNormal];
        [_newLabel1 setTitle:@"" forState:UIControlStateNormal];
//        [_newLabel1 addTarget:self action:@selector(clickEvent:) forControlEvents:UIControlEventTouchUpInside];
        _newLabel1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    }
    return _newLabel1;
}
-(UIButton*)morenewLabel
{
    if (!_morenewLabel) {
        _morenewLabel = [UIButton buttonWithType:UIButtonTypeCustom];
        _morenewLabel.backgroundColor =[UIColor clearColor];
        _morenewLabel.tag=0;
        _morenewLabel.userInteractionEnabled=YES;
        _morenewLabel.titleLabel.font = [UIFont systemFontOfSize:17];
        [_morenewLabel setTitleColor:adscolor forState:UIControlStateNormal];
        [_morenewLabel setTitle:@"" forState:UIControlStateNormal];
        [_morenewLabel addTarget:self action:@selector(clickEvent:) forControlEvents:UIControlEventTouchUpInside];
        _morenewLabel.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _morenewLabel.lineBreakMode = NSLineBreakByTruncatingTail;
        
    }
    return _morenewLabel;
}
-(UIButton*)morenewLabel1
{
    if (!_morenewLabel1) {
        _morenewLabel1 = [UIButton buttonWithType:UIButtonTypeCustom];
        _morenewLabel1.tag=1;
        _morenewLabel1.backgroundColor =[UIColor clearColor];
        _morenewLabel1.userInteractionEnabled=YES;
        _morenewLabel1.titleLabel.font = [UIFont systemFontOfSize:17];
        [_morenewLabel1 setTitleColor:UIColorHex(0xeb9a1a) forState:UIControlStateNormal];
        [_morenewLabel1 setTitle:@"" forState:UIControlStateNormal];
        [_morenewLabel1 addTarget:self action:@selector(clickEvent:) forControlEvents:UIControlEventTouchUpInside];
        _morenewLabel1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _morenewLabel1.lineBreakMode = NSLineBreakByTruncatingTail;
    }
    return _morenewLabel1;
}

-(void)clickEvent:(id)sender
{
    UIButton *btn = (UIButton *)sender;
    if (self.actionBlock) {
        NSArray *notices = (NSArray*)self.data;
        if (btn.tag>=notices.count) {
            return;
        }
        NoticesModel *noticemodel1 =[notices objectAtIndex:btn.tag];
        self.actionBlock(BEventType_Module,self,btn.tag,noticemodel1,self.indexPath);
    }
}
@end
